package com.dream.service.impl;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.dream.able.ArticleLableMapper;
import com.dream.datasource.DBContextHolder;
import com.dream.pojo.ArticleLable;
import com.dream.pojo.ArticleLableExample;
import com.dream.service.able.All_Service_able;

/*
 * 文章标签的业务类
 */
@Service("Article_lable_Serviceimpl")
public class Article_lable_Serviceimpl implements All_Service_able<ArticleLable>{
	
	/*
	 * 文章标签表DAO代理对象
	 */
	@Resource(name="articleLableMapper")
	private ArticleLableMapper article_lable_mapper;
	
	/*
	 * (添加一个文章标签，需要传入，标签内容)
	 * @see com.dream.service.able.All_Serviceable#insert(java.lang.String[])
 	 */
	@Override
	public ArticleLable insert(String... str) {
		//切换数据源，主库
		DBContextHolder.setDbType(DBContextHolder.master);
		//创建文章标签对象
		ArticleLable articleLable = new ArticleLable();
		//设置文章标签内容
		articleLable.setLable(str[0]);
		//设置状态
		articleLable.setState(1);
		//写入数据库
		return article_lable_mapper.insertSelective(articleLable)>0?articleLable:null;
	}

	/*
	 * (查询所有可用的文章标签)
	 * @see com.dream.service.able.All_Serviceable#list()
	 */
	@Override
	public List<ArticleLable> list() {
		//切换数据源，从库
		DBContextHolder.setDbType(DBContextHolder.slave);
		//创建查询工具类
		ArticleLableExample article_lable_example = new ArticleLableExample();
		//创建查询条件工具内部类
		ArticleLableExample.Criteria criteria = article_lable_example.createCriteria();
		//设置查询条件，state=1
		criteria.andStateEqualTo(1);
		//返回查询到的数据集
		return article_lable_mapper.selectByExample(article_lable_example);
	}

	@Override
	public ArticleLable getT(String... str) {
		// TODO Auto-generated method stub
		return null;
	}
}


